<?php

class HeaderBox extends AbstractBox {
	protected $template = 'main/header.tpl';
	
	protected function setup() {
		if (Utils::get('logintype') == 'logout') {
			Utils::redirect('uvod.html');
		}
		
		MySmarty::assign('baseURL', $GLOBALS['TSFE']->config['config']['baseURL']);
		MySmarty::assign('loggedUser', LoggedUser::whoIsLogged());
		
		$loggedUser = LoggedUser::whoIsLogged();
		if ($loggedUser) {
			$userRepository = new UserRepository();
			$userRepository->setAdditionalWhere(array(array('column' => 'is_online', 'value' => strtotime('-30 minutes'), 'xxx' => '>=')));
			MySmarty::assign('onlineUsersCount', $userRepository->getCountAll());
			
			$messageRepository = new MessageRepository();
			$unreadMessages = $messageRepository->getCountByFkToUserIdAndIsRead($loggedUser['uid'], 0);
			MySmarty::assign('unreadMessages', $unreadMessages);
		}
	}
}

?>